package com.dqyt.khjc.controller;

import com.alibaba.fastjson.JSON;
import com.dqyt.khjc.bean.ResultMsg;
import com.dqyt.khjc.service.SamplePcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 样品信息 pc端使用
 */
@RestController
public class SamplePcController {

    @Autowired
    private SamplePcService samplePcService;

    /**
     * 查询样品信息
     * @param request
     * @param type  类型
     * @param sbbh  设备编号
     * @param bsbh 标识编号
     * @param erweima 二维码
     * @return
     */
    @RequestMapping(value = "/api/getPcSample", method = {RequestMethod.GET,RequestMethod.POST})
    public ResultMsg getPcSample(HttpServletRequest request, int type,String sbbh, String bsbh, String erweima) {
        ResultMsg resultMsg =samplePcService.getPcSample(request,type,sbbh,bsbh,erweima);
        return resultMsg;
    }


    /**
     * 更具设备编号查询样品信息
     * @param request
     * @param type  类型
     * @param sbbh  设备编号
     * @return
     */
    @RequestMapping(value = "/api/getPcSample2", method = {RequestMethod.GET,RequestMethod.POST})
    public ResultMsg getPcSample2(HttpServletRequest request,int type,String sbbh, String bsbh, String erweima) {
        ResultMsg resultMsg =samplePcService.getPcSample2(request,type,sbbh,bsbh,erweima);
        return resultMsg;
    }



    /**
     * 根据标识编号查询 样品信息
     * @param request
     * @param bsbh
     * @return
     */
    @RequestMapping(value = "/api/getPcSampleByBsbh", method = {RequestMethod.POST})
    public  ResultMsg getPcSampleByBsbh(HttpServletRequest request,String bsbh){
        ResultMsg resultMsg =samplePcService.getPcSampleByBsbh(request,bsbh);
        return resultMsg;
    }


    /**
     * 查询样品信息 根据id
     *
     * @param request
     * @param bsbh
     * @return
     */
    @RequestMapping(value = "/api/getPcSampleBypr", method = {RequestMethod.GET,RequestMethod.POST})
    public ResultMsg getPcSampleBypr(HttpServletRequest request,  String bsbh,String erweima) {
        ResultMsg resultMsg =samplePcService.getPcSampleBypr(request,bsbh,erweima);
        return resultMsg;
    }


    /**
     * 新增样品信息
     * @param request
     * @param sample
     * @return
     */
    @RequestMapping(value = "/api/savePcSample", method = {RequestMethod.GET,RequestMethod.POST})
    public ResultMsg savePcSample(HttpServletRequest request,String sample){
        ResultMsg resultMsg =samplePcService.savePcSample(request,sample);
        return resultMsg;
    }


    /**
     * 修改样品信息
     * @param request
     * @param sample
     * @return
     */
    @RequestMapping(value = "/api/upfatePcSample", method = {RequestMethod.GET,RequestMethod.POST})
    public ResultMsg upfatePcSample(HttpServletRequest request,String sample){
        ResultMsg resultMsg =samplePcService.upfatePcSample(request,sample);
        return resultMsg;
    }


    /**
     * 分页查询样品
     * @param request 请求
     * @param pageNum  页数
     * @param pageSize  每页条数
     * @param bsbh   标识编号
     * @param erweima  二维码
     * @param type  样品类型  1：呼吸器  2: 复合气瓶
     * @param sampleStatue    设备状态   1：已接受   2：检测中 3：检测不合格 4：合格 5：维修中 6:已废弃
     * @param wtfId  委托方id
     * @param s_sbbh  查询条件 设备编号
     * @return
     */
    @RequestMapping(value = "/api/getSampleListPage", method = {RequestMethod.POST})
    public ResultMsg getSampleListPage(HttpServletRequest request,
                                       @RequestParam(defaultValue = "1") Integer pageNum,
                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                       @RequestParam(name = "bsbh", required = false, defaultValue = "")  String bsbh,
                                       @RequestParam(name = "erweima", required = false, defaultValue = "")  String erweima,
                                       @RequestParam(defaultValue = "0")Integer type,
                                       @RequestParam(defaultValue = "0") Integer sampleStatue,
                                       @RequestParam(defaultValue = "-1") Integer wtfId,
                                       @RequestParam(defaultValue = "-1") Integer wtfIdChi,
                                       @RequestParam(name = "s_sbbh", required = false, defaultValue = "") String s_sbbh,
                                       @RequestParam(name = "zzcsId", required = false, defaultValue = "") String zzcsId,
                                       @RequestParam(name = "rwdbh", required = false, defaultValue = "") String rwdbh,
                                       @RequestParam(name = "jcrId", required = false, defaultValue = "") String jcrId){

        ResultMsg resultMsg = samplePcService.getSampleListPage(request,pageNum, pageSize, bsbh, erweima, type, sampleStatue, wtfId,wtfIdChi, s_sbbh,zzcsId,rwdbh,jcrId);
        return resultMsg;
    }



    /**
     * 分页查询我的样品
     * @param request 请求
     * @param pageNum  页数
     * @param pageSize  每页条数
     * @param bsbh   标识编号
     * @param erweima  二维码
     * @param type  样品类型  1：呼吸器  2: 复合气瓶
     * @param sampleStatue    设备状态   1：已接受   2：检测中 3：检测不合格 4：合格 5：维修中 6:已废弃
     * @param wtfId  委托方id
     * @param s_sbbh  查询条件 设备编号
     * @return
     */
    @RequestMapping(value = "/api/getSampleMeListPage", method = {RequestMethod.POST})
    public ResultMsg getSampleMeListPage(HttpServletRequest request,
                                       @RequestParam(defaultValue = "1") Integer pageNum,
                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                       @RequestParam(name = "bsbh", required = false, defaultValue = "")  String bsbh,
                                       @RequestParam(name = "erweima", required = false, defaultValue = "")  String erweima,
                                       @RequestParam(defaultValue = "0")Integer type,
                                       @RequestParam(defaultValue = "0") Integer sampleStatue,
                                       @RequestParam(defaultValue = "-1") Integer wtfId,
                                         @RequestParam(defaultValue = "-1") Integer wtfIdChi,
                                       @RequestParam(name = "s_sbbh", required = false, defaultValue = "") String s_sbbh,
                                       @RequestParam(name = "zzcsId", required = false, defaultValue = "") String zzcsId,
                                       @RequestParam(name = "rwdbh", required = false, defaultValue = "") String rwdbh){

        ResultMsg resultMsg = samplePcService.getSampleMeListPage(request,pageNum, pageSize, bsbh, erweima, type, sampleStatue, wtfId,wtfIdChi, s_sbbh,zzcsId,rwdbh);
        return resultMsg;
    }


    /**
     * 补打二维码 查询列表  分页
     * @param request
     * @param pageNum
     * @param pageSize
     * @param bsbh
     * @param sbbh
     * @return
     */
    @RequestMapping(value = "/api/getSampleListPdewm", method = {RequestMethod.POST})
    public ResultMsg getSampleListPdewm(HttpServletRequest request,
                                        @RequestParam(defaultValue = "1") Integer pageNum,
                                        @RequestParam(defaultValue = "10") Integer pageSize,
                                        @RequestParam(name = "type", required = false, defaultValue = "")  Integer type,
                                        @RequestParam(name = "bsbh", required = false, defaultValue = "")  String bsbh,
                                        @RequestParam(name = "sbbh", required = false, defaultValue = "") String sbbh,
                                        @RequestParam(name = "jcrId", required = false, defaultValue = "") String jcrId){


        if (type==null){
            type=0;
        }
        ResultMsg resultMsg = samplePcService.getSampleListPdewm(request,pageNum,pageSize,type,bsbh, sbbh,jcrId);
        return resultMsg;
    }



    /**
     * 查询面罩的列表信息  根据条件
     * @param request
     * @param pageNum
     * @param pageSize
     * @param bsbh
     * @param sbbh
     * @return
     */
    @RequestMapping(value = "/api/getSampleListZt", method = {RequestMethod.POST})
    public ResultMsg getSampleListZt(HttpServletRequest request,
                                        @RequestParam(defaultValue = "1") Integer pageNum,
                                        @RequestParam(defaultValue = "10") Integer pageSize,
                                        @RequestParam(name = "type", required = false, defaultValue = "")  int type,
                                        @RequestParam(name = "bsbh", required = false, defaultValue = "")  String bsbh,
                                        @RequestParam(name = "qpbsh", required = false, defaultValue = "")  String qpbsh,
                                        @RequestParam(name = "sbbh", required = false, defaultValue = "") String sbbh,
                                        @RequestParam(name = "rwdbh", required = false, defaultValue = "") String rwdbh){

        ResultMsg resultMsg = samplePcService.getSampleListZt(request,pageNum, pageSize, type,bsbh,qpbsh, sbbh,rwdbh);
        return resultMsg;
    }


    /**
     * 查询面罩绑定气瓶信息
     * @param request
     * @param pageNum
     * @param pageSize
     * @param bsbh
     * @param sbbh
     * @return
     */
    @RequestMapping(value = "/api/getSampleBind", method = {RequestMethod.POST})
    public ResultMsg getSampleBind(HttpServletRequest request,
                                        @RequestParam(defaultValue = "1") Integer pageNum,
                                        @RequestParam(defaultValue = "10") Integer pageSize,
                                        @RequestParam(name = "bsbh", required = false, defaultValue = "")  String bsbh,
                                        @RequestParam(name = "type", required = false, defaultValue = "")  int type,
                                        @RequestParam(name = "sbbh", required = false, defaultValue = "") String sbbh){

        ResultMsg resultMsg = samplePcService.getSampleListPdewm(request,pageNum, pageSize, type, bsbh,sbbh,"");
        return resultMsg;
    }

    /**
     * 查询为分配的 任务的 样品
     * @param bsbh   标识编号
     * @param type  样品类型  1：呼吸器  2: 复合气瓶
     * @return
     */
    @RequestMapping(value = "/api/getSampleListWorkAll")
    public ResultMsg getSampleListWorkAll(HttpServletRequest request,
                                          @RequestParam(name = "bsbh", required = false, defaultValue = "")  String bsbh,
                                          @RequestParam(defaultValue = "0")Integer type){

        ResultMsg resultMsg = samplePcService.getSampleListWorkAll(request, bsbh, type);
        return resultMsg;
    }



    /**
     * 分配任务
     * @return
     */
    @RequestMapping(value = "/api/assignTasks")
    public ResultMsg assignTasks(HttpServletRequest request,String [] bsbhArrar,String jcrUserId,String jcrStr){
        ResultMsg resultMsg = samplePcService.assignTasks(request, bsbhArrar, jcrUserId,jcrStr);
        return resultMsg;
    }


    /**
     * 分配任务
     * @return
     */
    @RequestMapping(value = "/api/deleteSamp")
    public ResultMsg deleteSamp(HttpServletRequest request,String bh,String bsbh){
        ResultMsg resultMsg = samplePcService.deleteSamp(request, bh, bsbh);
        return resultMsg;
    }


    /**
     * 修改整机气密性
     * @return
     */
    @RequestMapping(value = "/api/updateZjqmxBjsq")
    public ResultMsg updateZjqmxBjsq(HttpServletRequest request,String bh,String zjqmx,String bjsq){
        ResultMsg resultMsg = samplePcService.updateZjqmxBjsq(request, bh, zjqmx, bjsq);
        return resultMsg;
    }


    /**
     * 添加任务单号和 检验员
     * @return
     */
    @RequestMapping(value = "/api/addRwdbhOrJyy")
    public ResultMsg addRwdbhOrJyy(HttpServletRequest request,String bh,String rwdbh,String jcr,String jcrId){
        ResultMsg resultMsg = samplePcService.addRwdbhOrJyy(request,bh, rwdbh, jcr, jcrId);
        return resultMsg;
    }





}
